Randomizer.prototype.TickTime = 50;
Randomizer.prototype.TickNumber = 20;
Randomizer.prototype.SlowTicks = 12;
Randomizer.prototype.ResultDelay = 300;

// Randomizer constructor
function Randomizer(question, options) {
    this.question = question;
    this.options = options;
    this.selected = 0;
	this.ticks = this.TickNumber;
}

Randomizer.prototype.SetCaption = function(){
    $("caption").html(this.question);
};

Randomizer.prototype.GetTickTime = function(){	
    if (this.ticks>0) {
	   return this.TickTime;
	}
	else {
		return this.TickTime + Math.pow(2,Math.abs(this.ticks));
	}
};

Randomizer.prototype.Rand = function(){
    this.ticks = this.ticks - 1;
    this.SetRandom();
    var randObj = this;
    if(this.ticks > (-1)*this.SlowTicks){
        setTimeout(function() { randObj.Rand(); },this.GetTickTime());
    }
    else {
        setTimeout(function() { randObj.EndRand(); },this.ResultDelay);
    }
};

Randomizer.prototype.EndRand = function(){
    $("#randtable tbody").hide();
    this.DisplayResult();
    $("#randtable tbody").fadeIn("slow");
};

Randomizer.prototype.DisplayOptions = function(){
    var optTable = $("#randtable tbody");
    optTable.empty();
    for (var i=0; i<this.options.length; i++) {
      optTable.append('<tr><td class="num">' + (i+1) + '.</td><td>'+this.options[i]+'</td></tr>');
    };
};

Randomizer.prototype.DisplayResult = function(){
    var optTable = $("#randtable tbody");
    optTable.empty();
    optTable.append('<tr class=result><td>' +this.options[this.selected]+'</td></tr>');
};

Randomizer.prototype.SetRandom = function(){
    this.selected = parseInt(Math.random()*this.options.length);
    $("#randtable tr").removeClass("selected");
    $("#randtable tr").eq(this.selected).addClass("selected");
};